package com.example.logistics_manage.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.logistics_manage.mapper.NewsMapper;
import com.example.logistics_manage.pojo.News;
import com.example.logistics_manage.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author quhao
 * @since 1.0
 */
@Service
public class NewsService extends ServiceImpl<NewsMapper, News> implements INewsService {
    @Autowired
    private NewsMapper newsMapper;

    @Override
    public List<News> selectAllNews() {
        return this.list();
    }

    @Override
    public void updateNews(News news) {
        newsMapper.updateById(news);
    }

    @Override
    public void deleteNews(Integer newsId) {
        newsMapper.deleteById(newsId);
    }

    @Override
    public List<News> selectByTitle(String title) {
        Wrapper<News> wrapper = new LambdaQueryWrapper<News>().like(News::getTitle,title);
        return newsMapper.selectList(wrapper);
    }

    @Override
    public void insertNews(News news) {
        save(news);
    }
}
